<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/wx/conf/account" data-pjax><i
                class="ti-angle-left"></i> 返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/wx/conf/account/addDo" method="post">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="url" class="col-sm-2 control-label">URL</label>

                            <div id="url" class="col-sm-8" style="padding-top: 10px;">
                                ${AppDomain!}${base!}/open/weixin/api/:id
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="appname" class="col-sm-2 control-label">公众号名称</label>

                            <div class="col-sm-8">
                                <input type="text" id="appname" class="form-control" name="appname"
                                       data-parsley-required="true"
                                       placeholder="公众号名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="ghid" class="col-sm-2 control-label">原始ID</label>

                            <div class="col-sm-8">
                                <input type="text" id="ghid" class="form-control" name="ghid"
                                       placeholder="原始ID">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="appid" class="col-sm-2 control-label">Appid</label>

                            <div class="col-sm-8">
                                <input type="text" id="appid" class="form-control" name="appid"
                                       data-parsley-required="true"
                                       placeholder="appid">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="appsecret" class="col-sm-2 control-label">Appsecret</label>

                            <div class="col-sm-8">
                                <input type="text" id="appsecret" class="form-control" name="appsecret"
                                       data-parsley-required="true"
                                       placeholder="appsecret">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="encodingAESKey" class="col-sm-2 control-label">EncodingAESKey</label>

                            <div class="col-sm-8">
                                <input type="text" id="encodingAESKey" class="form-control" name="encodingAESKey"
                                       data-parsley-required="true"
                                       placeholder="encodingAESKey">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="token" class="col-sm-2 control-label">Token</label>

                            <div class="col-sm-8">
                                <input type="text" id="token" class="form-control" name="token"
                                       data-parsley-required="true"
                                       placeholder="token">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">微信支付</label>
                            <div class="col-sm-8" style="padding-top: 5px;">
                                <input type="radio" name="payEnabled" value="1" checked>启用
                                <input type="radio" name="payEnabled" value="0">禁用
                                <button class="btn btn-info" type="button" id="btnWxpay"> 配置
                                </button>
                                <textarea name="payInfo" id="payInfo" hidden>{}</textarea>

                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button id="save" type="button" class="btn btn-primary btn-block btn-lg btn-parsley"
                                    data-loading-text="正在提交...">提 交
                            </button>
                        </div>
                    </div>
                </div>
            </form>
        </section>

    </div>
</div>
<div id="dialogWxpay" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">微信支付配置</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">Mchid</label>
                        <div class="col-sm-7" style="padding-bottom: 5px;">
                            <input id="wxpay_mchid" type="text" class="form-control" value="">

                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">key</label>
                        <div class="col-sm-7" style="padding-bottom: 5px;">
                            <input id="wxpay_key" type="text" class="form-control" value="">

                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">请在微信后台添加支付授权目录</label>
                        <div class="col-sm-7" style="padding-bottom: 5px;">
                            ${AppDomain!}${base!}/open/pay/
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">请将证书文件放至</label>
                        <div class="col-sm-7" style="padding-bottom: 5px;">
                            /WEB-INF/cert/wxpay/
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button id="btnWx" type="button" class="btn btn-default" data-dismiss="modal">清 除</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal" data-loading-text="确定...">确 定
                </button>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">
    $(document).ready(function () {
        $("#btnWxpay").on("click",function () {
            var wxpay=JSON.parse($("#payInfo").val());
            if(wxpay.wxpay_mchid)$("#wxpay_mchid").val(wxpay.wxpay_mchid);
            if(wxpay.wxpay_key)$("#wxpay_key").val(wxpay.wxpay_key);
            if(wxpay.wxpay_appsecret)$("#wxpay_appsecret").val(wxpay.wxpay_appsecret);
            $("#dialogWxpay").modal();
        });
        $("#btnWx").on("click", function () {
            $("#dialogWxpay input[type=text]").each(function () {
                $(this).val("");
            });
        });
        $("#save").on("click", function () {
            var wxpay = {};
            wxpay.wxpay_mchid = $("#wxpay_mchid").val();
            wxpay.wxpay_key = $("#wxpay_key").val();
            wxpay.wxpay_appsecret = $("#wxpay_appsecret").val();
            $("#payInfo").val(JSON.stringify(wxpay));
            $('#addForm').submit();
        });
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code == 0) {
                    Toast.success(data.msg);
                    //刷新父级菜单
                    form.resetForm();
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
    });
</script>

<%}%>